/**
 * Copyright &copy; 2015-2020 <a href="http://www.easyhis.com/">easyhis</a> All rights reserved.
 */
package com.easy.modules.iim.entity;

import com.easy.common.utils.IdGen;
import com.easy.common.utils.SpringContextHolder;
import com.easy.common.utils.StringUtils;
import com.easy.common.utils.excel.annotation.ExcelField;
import com.easy.core.persistence.BaseEntity;
import com.easy.modules.sys.entity.User;
import com.easy.modules.sys.utils.UserUtils;
import com.google.common.collect.Lists;
import org.hibernate.validator.constraints.Length;

import java.util.Date;
import java.util.List;

/**
 * 群组Entity
 * @author lgf
 * @version 2016-08-07
 */
public class LayGroup extends BaseEntity<LayGroup> {
	
	private static final long serialVersionUID = 1L;
	private Integer groupId;
	private String id;
	private String groupName;		// 群组名
	private String avatar;		// 群头像
	private List<LayGroupUser> layGroupUserList = Lists.newArrayList();		// 子表列表
	protected String remarks;	// 备注
	protected User createBy;	// 创建者
	protected Date createTime;	// 创建日期
	protected User updateBy;	// 更新者
	protected Date updateTime;	// 更新日期
	protected Integer delFlag; 	// 删除标记（0：正常；1：删除；2：审核）


	public LayGroup() {
		super();
	}

	public LayGroup(Integer groupId){
		this.groupId = groupId;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Integer getGroupId() {
		return groupId;
	}

	public void setGroupId(Integer groupId) {
		this.groupId = groupId;
	}

	@Length(min=0, max=64, message="群组名长度必须介于 0 和 64 之间")
	@ExcelField(title="群组名", align=2, sort=1)
	public String getGroupName() {
		return groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}
	
	@Length(min=0, max=256, message="群头像长度必须介于 0 和 256 之间")
	@ExcelField(title="群头像", align=2, sort=2)
	public String getAvatar() {
		if(StringUtils.isBlank(avatar)){
			return SpringContextHolder.getStatic()+"/common/images/flat-avatar.png";
		}
		return avatar;
	}

	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}
	
	public List<LayGroupUser> getLayGroupUserList() {
		return layGroupUserList;
	}

	public void setLayGroupUserList(List<LayGroupUser> layGroupUserList) {
		this.layGroupUserList = layGroupUserList;
	}


	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public User getCreateBy() {
		return createBy;
	}

	public void setCreateBy(User createBy) {
		this.createBy = createBy;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public User getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(User updateBy) {
		this.updateBy = updateBy;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public Integer getDelFlag() {
		return delFlag;
	}

	public void setDelFlag(Integer delFlag) {
		this.delFlag = delFlag;
	}

	/**
	 * 插入之前执行方法，需要手动调用
	 */
	public void preInsert(){
		User user = UserUtils.getUser();
		if (user.getUserId()<1){
			this.updateBy = user;
			this.createBy = user;
		}
		this.updateTime = new Date();
		this.createTime = this.updateTime;
	}

	/**
	 * 更新之前执行方法，需要手动调用
	 */
	public void preUpdate(){
		User user = UserUtils.getUser();
		if (user.getUserId()<1){
			this.updateBy = user;
		}
		this.updateTime = new Date();
	}
}